package cc.md888.app.web.controller;

import cc.md888.app.application.activatecode.ActivateCodeService;
import cc.md888.app.application.user.UserService;
import cc.md888.app.model.activatecode.ActivateCodeVO;
import cc.md888.app.model.user.*;
import cc.md888.result.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private ActivateCodeService activateCodeService;

    @Autowired
    private UserService userService;

    /**
     * 发送邮件验证码
     * @param cmd
     * @return
     */
    @PostMapping("/sendActivateEmail")
    public Result<ActivateCodeVO> sendActivateEmail(@RequestBody SendActivateEmailCmd cmd){
        return Result.ok(
                activateCodeService.sendActivateEmail(cmd)
        );
    }


    /**
     * 邮箱注册
     * @param cmd
     * @return
     */
    @PostMapping("/registerByEmail")
    public Result<RegistrationResultVO> registerByEmail(@RequestBody EmailRegistrationCmd cmd){
        return Result.ok(
                userService.registerByEmail(cmd)
        );
    }


    /**
     * 登录
     * @param cmd
     * @return
     */
    @PostMapping("/login")
    public Result<LoginResultVO> login(@RequestBody UserLoginCmd cmd){
        return Result.ok(
                userService.login(cmd)
        );
    }
}
